package com.cw1.design1Single;

/**
 * @Author qiuMi
 * @description 懒汉式 - 线程安全
 * @Date 2022-09-26 22:19
 **/
public class SingleTest04 {
    public static void main(String[] args) {

    }
}

/**
 * synchronized 实现
 * 懒汉式 - 线程安全
 */
class Single4{
    public static Single4 instance;

    /**
     * 当调用 getInstance 才创建单例对象 - 懒汉式
     * @return Single4
     */
    public synchronized Single4 getInstance(){
        if (null == instance){
            instance = new Single4();
        }
        return instance;
    }
}
